﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Interfaces;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Twodi.Aspect.Implemented
{
    public abstract class AbstractTextureAspect : AbstractAspect, ITexture
    {
        /// <summary>
        /// Alpha color a ser usada durante o Draw.
        /// </summary>
        protected Color alphaColor = Color.White;

        /// <summary>
        /// Retangulo de Source da Textura.
        /// </summary>
        protected Rectangle? source = null;

        /// <summary>
        /// Textura do componente.
        /// </summary>
        public virtual Texture2D Texture
        {
            get;
            set;
        }

        /// <summary>
        /// Alpha color a ser usada durante o Draw.
        /// </summary>
        public Color AlphaColor
        {
            get { return this.alphaColor; }
            set
            {
                this.alphaColor = value;
                onAlphaColorChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        /// Retangulo de Source da Textura.
        /// </summary>
        public Rectangle? Source
        {
            get { return this.source; }
            set
            {
                this.source = value;
                onSourceChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        /// Evento invocado caso a textura for alterada.
        /// </summary>
        public event EventHandler<EventArgs> TextureChanged;

        /// <summary>
        /// Evento invocado caso alpha color for alterada.
        /// </summary>
        public event EventHandler<EventArgs> AlphaColorChanged;

        /// <summary>
        /// Evento invocado caso o source for alterado.
        /// </summary>
        public event EventHandler<EventArgs> SourceChanged;

        protected virtual void onTextureChanged(EventArgs e)
        {
            if (TextureChanged != null)
            {
                TextureChanged(this, e);
            }
        }

        protected virtual void onAlphaColorChanged(EventArgs e)
        {
            if (AlphaColorChanged != null)
            {
                AlphaColorChanged(this, e);
            }
        }

        protected virtual void onSourceChanged(EventArgs e)
        {
            if (SourceChanged != null)
            {
                SourceChanged(this, e);
            }
        }
    }
}
